#include<bits/stdc++.h>
using namespace std;
int T,a[200005],mark[200005],minred,minblue,ans,n;
void dfs(int num){
    if(num==n+1){
        int sum=0;
        for(int i=1;i<=n;i++){
            if(mark[i]==1){
                if(a[minred]==a[i])
                sum+=a[i];
                minred=i;
            }
            if(mark[i]==2){
                if(a[minblue]==a[i])
                sum+=a[i];
                minblue=i;
            }
        }
        ans=max(ans,sum);
        return;
    }
    mark[num]=1;
    dfs(num+1);
    mark[num]=2;
    dfs(num+1);
}
void solve(){
    ans=0;
    minred=minblue=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    memset(mark,0,sizeof(mark));
    dfs(1);
    cout<<ans<<endl;
}
int main(){
    freopen("color1.in","r",stdin);
    cin>>T;
    while(T--)
    solve();
    return 0;
}
